Other Functions

The following functions are available globally.

  • Helper function to ensure that the callback is executed on the main thread.

    Declaration

    Swift

    public func callOnMainThread(_ callback: ((Void) -> Void))
  • Attempt to create an enum for the given key in the given dictionary, filling presentKeys and errors along the way.

    Declaration

    Swift

    public func createEnum<E: RawRepresentable>(type: E.Type, for key: String, in json: FHIRJSON, context: inout FHIRInstantiationContext) -> E?

    Parameters

    type

    The enum type to create (as an array)

    key

    The JSON key to look at in json

    json

    The JSON dictionary to inspect

    context

    The instantiation context to use

    Return Value

    An array of enums, or nil

  • Attempt to create an array of enums for the given key in the given dictionary, populating presentKeys and errors appropriately.

    Declaration

    Swift

    public func createEnums<E: RawRepresentable>(of type: E.Type, for key: String, in json: FHIRJSON, context: inout FHIRInstantiationContext) -> [E]?

    Parameters

    type

    The enum type to create (as an array)

    key

    The JSON key to look at in json

    json

    The JSON dictionary to inspect

    context

    The instantiation context to use

    Return Value

    An array of enums, or nil

  • Undocumented

  • Inspects the given dictionary for an array with the given key, and if successful instantiates an array of the desired FHIR objects.

    Unable to make this a class method on FHIRAbstractBase as it would need to be implemented on every subclass in order to not return FHIRAbstractBase all the time.

    Declaration

    Swift

    public func instantiate<T: FHIRAbstractBase>(type: T.Type, for key: String, in json: FHIRJSON, presentKeys: inout Set<String>, errors: inout [FHIRValidationError], owner: FHIRAbstractBase? = nil) throws -> [T]?

    Parameters

    type

    The FHIR object that is expected

    key

    The key for which to look in json

    json

    The JSON dictionary to search through

    presentKeys

    An inout set of keys found in the JSON

    errors

    An inout array of validation errors found

    owner

    The FHIRAbstractBase owning the new instance, if appropriate

    Return Value

    An array of the desired FHIRAbstractBase subclasses (or nil)

  • Inspects the given dictionary for the value of the given key, then instantiates the desired type if possible.

    Cannot implement this as init?() throws because it needs to inspect P.JSONType before calling init(), which is not possible.

    Declaration

    Swift

    public func createInstance<P: FHIRJSONType>(type: P.Type, for key: String, in json: FHIRJSON, context: inout FHIRInstantiationContext, owner: FHIRAbstractBase?) -> P?

    Parameters

    type

    The primitive type that is wanted

    key

    The key for which to look in json

    json

    The JSON dictionary to search through

    context

    The instantiation context to use

    owner

    The FHIRAbstractBase owning the new instance, if appropriate

    Return Value

    An instance of the appropriate FHIRPrimitive, or nil

  • Inspects the given dictionary for an array with the given key, and if successful instantiates an array of the desired types.

    This method cannot be part of FHIRJSONType because it would have to be implemented by every resource class, instead of just the base class (error is “Protocol requirement cannot be satisfied by non-final class because it uses ‘Self’ in a non-parameter, non-result type position).

    Declaration

    Swift

    public func createInstances<P: FHIRJSONType>(of type: P.Type, for key: String, in json: FHIRJSON, context: inout FHIRInstantiationContext, owner: FHIRAbstractBase?) -> [P]?

    Parameters

    type

    The primitive type that is expected

    key

    The key for which to look in json

    json

    The JSON dictionary to search through

    context

    The instantiation context to use

    owner

    The FHIRAbstractBase owning the new instance, if appropriate

    Return Value

    An array of the appropriate FHIRPrimitive, or nil

  • Execute a print(), prepending filename, line and function/method name, if DEBUG is defined.

    Declaration

    Swift

    public func fhir_logIfDebug(_ message: @autoclosure () -> String, function: String = #function, file: String = #file, line: Int = #line)
  • Execute a print(), prepending filename, line and function/method name and WARNING prepended.

    Declaration

    Swift

    public func fhir_warn(_ message: @autoclosure () -> String, function: String = #function, file: String = #file, line: Int = #line)